package main_com.mapper;

import main_com.pojo.LoginBean;
import main_com.pojo.LookMessageBean;
import main_com.pojo.UserBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;

@Mapper
public interface UserMapper {
    @Select("select count(*) from user where userName=#{userName} and password=#{password}")
    int findLoginBean(LoginBean loginBean);

    @Select("select userName, password from user where userName=#{userName}")
    LoginBean getLoginBeanByUserName(String userName);

    @Select("select name,sex,birth,nation,edu,work,phone,place,email from user where userName=#{userName}")
    ArrayList<LookMessageBean> getMessageBeansByUserName(String userName);

    @Select("select count(*) from user where userName=#{userName}")
    int findUserName(String userName);

    @Insert("insert into user values(#{userName}, #{password}, #{name}, #{sex}, #{birth}, #{nation}, #{edu}, #{work}, #{phone}, #{place}, #{email})")
    void insertUser(UserBean userBean);

    @Update("Update user set edu=#{edu},work=#{work},phone=#{phone},email=#{email} where userName=#{userName}")
    void updateUserEWPEByUserName(String edu, String work, String phone, String email, String userName);

    @Update("Update user set password=#{password} where userName=#{userName}")
    void updatePasswordByUserName(String userName, String password);
}
